package com.iot.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.iot.framework.rabbitmq.service.DeviceAlarmService;
import com.iot.framework.rabbitmq.service.DeviceStateService;
import com.iot.system.core.CoreDeviceStateService;
import com.iot.system.domain.vo.DeviceStateVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.iot.common.annotation.Log;
import com.iot.common.core.controller.BaseController;
import com.iot.common.core.domain.AjaxResult;
import com.iot.common.enums.BusinessType;
import com.iot.system.domain.DeviceState;
import com.iot.system.service.IDeviceStateService;
import com.iot.common.utils.poi.ExcelUtil;
import com.iot.common.core.page.TableDataInfo;

/**
 * 设备状态管理
 * 
 * @author iot
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/system/state")
public class DeviceStateController extends BaseController
{

    @Autowired
    private CoreDeviceStateService coreDeviceStateService;

    @Autowired
    private DeviceStateService deviceStateService;

    @Autowired
    private DeviceAlarmService deviceAlarmService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('results:state:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceState deviceState)
    {
        startPage();
        List<DeviceStateVo> list = coreDeviceStateService.selectDeviceStateList(deviceState);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('results:state:export')")
    @Log(title = "导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceState deviceState)
    {
        List<DeviceStateVo> list = coreDeviceStateService.selectDeviceStateList(deviceState);
        ExcelUtil<DeviceStateVo> util = new ExcelUtil<DeviceStateVo>(DeviceStateVo.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('results:state:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(coreDeviceStateService.selectDeviceStateById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('results:state:add')")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceState deviceState)
    {
        return toAjax(coreDeviceStateService.insertDeviceState(deviceState));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('results:state:edit')")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceState deviceState)
    {
        return toAjax(coreDeviceStateService.updateDeviceState(deviceState));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('results:state:remove')")
    @Log(title = "删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(coreDeviceStateService.deleteDeviceStateByIds(ids));
    }

    @PostMapping("/saveDeviceStatus")
    public AjaxResult saveDeviceStatus(@RequestBody String s)
    {
        AjaxResult ajaxResult = success();
        deviceStateService.deviceState(s);
        return ajaxResult;
    }


/*    @PostMapping("/deviceAlarm")
    public AjaxResult deviceAlarm(@RequestBody String s)
    {
        AjaxResult ajaxResult = success();
        deviceAlarmService.deviceAlarm(s);
        return ajaxResult;
    }*/
}
